<?php
//print_r($_POST);
if(isset($_POST[txtDeviceId]) && $_POST[txtDeviceId] !='')
{
	$sql = "SELECT * FROM tb_deviceinfo,tb_device_model WHERE id = di_deviceModel AND di_id =".$_POST[txtDeviceId];
	$rows = $db->query($sql);
	if($db->affected_rows > 0)
	{
		$deviceRecord = $db->fetch_array($rows);
		/*if($deviceRecord[di_Fuelport] != 0)
			$totInput = $deviceRecord[tdm_noofInputs]-1;
		else */
		$totInput = $deviceRecord[tdm_noofInputs];
		$totOutput = $deviceRecord[tdm_noofOutputs];
		$totAnalog = $deviceRecord[tdm_noofAnalog];
		$readonly = 'readonly="readonly"';
	}
	else
	{
		$sql = "SELECT * FROM tb_deviceinfo,tb_device_model WHERE di_id =".$_POST[txtDeviceId];
		$rows = $db->query($sql);
		if($db->affected_rows > 0)
		{
			$deviceRecord = $db->fetch_array($rows);
		}
	}
}
$sql = "SELECT ci_id,ci_clientName,ui_id FROM tb_clientinfo,tb_userinfo WHERE ui_isAdmin = 1 AND ui_clientId = ci_id AND ci_id=".$_POST[txtClientId];
$rows = $db->query($sql);
$clientRecord = $db->fetch_array($rows);
	

$dev_model_query = "SELECT * FROM tb_device_model";
$model_rows = $db->query($dev_model_query);
?>
<script language="javascript">

var intTextBox=0;

function addRow(tableID,labTxt,inpTxt) 
{
	var table = document.getElementById("divFixedNumber"+tableID);

	var rowCount = table.rows.length;
	var row = table.insertRow(rowCount);
	
	var cell0 = row.insertCell(0);
	cell0.innerHTML = rowCount;
			
	var cell1 = row.insertCell(1);
	var element1 = document.createElement("input");
	element1.type = "text";
	element1.name = tableID+"txtTankSize"+rowCount;
	element1.id = tableID+"txtTankSize"+rowCount;
	element1.value = labTxt;
	element1.style.width = "40%";
	cell1.appendChild(element1);

	var cell2 = row.insertCell(2);
	var element2 = document.createElement("input");
	element2.type = "text";
	element2.name = tableID+"txtVoltage"+rowCount;
	element2.id = tableID+"txtVoltage"+rowCount;
	element2.value = inpTxt;
	element2.style.width = "40%";
	cell2.appendChild(element2);
	
	var cell3 = row.insertCell(3);
	cell3.innerHTML +="<a href='javascript:void(0);' onclick='deleteRow("+tableID+","+rowCount+")'  name='landNumberDelete'>&nbsp;&nbsp;[-]</a>";

}

function deleteRow(tableID,rowCount) 
{
	try {
	var table = document.getElementById("divFixedNumber"+tableID);
	var rowCount = table.rows.length;
	table.deleteRow(rowCount-1);
	}catch(e) {
		alert(e);
	}
}
function generateRow(tabIndex,data)
{
	v1 = data.split("#")
	for(k = 0; k < v1.length-1; k++)		
	{
		v2 = v1[k].split("_");			
		addRow(tabIndex,v2[0],v2[1])
	}
}

var addFixedNumber = function(v){
	intTextBox = intTextBox + 1;
	
	var tbl = document.getElementById("divFixedNumber"+v);
	var lastRow = tbl.rows.length;
  	var iteration = lastRow;
  	var newRow = tbl.insertRow(lastRow);
  	var oCell = newRow.insertCell();
	oCell.innerHTML = "<input type='text' name='t1'>";
	
	oCell = newRow.insertCell();
	oCell.innerHTML = "<input type='text' name='t2'>";
	
	/*var contentID = document.getElementById("fixed-col"+v);
	var newTBDiv = document.createElement("div");
	newTBDiv.setAttribute("id","strTextPn"+intTextBox);
	newTBDiv.innerHTML = "<br /><input type ='text' name='tanksize"+v+"[]' id='tanksize' style='width:70px;' maxlength='5' >&nbsp;&nbsp;<input type='text' style='width:70px;' id='" + intTextBox + "' name='voltage"+v+"[]' maxlength='8'><a href='javascript:void(0);' onclick='removeFixedNumber("+intTextBox+")'  name='landNumberDelete'>&nbsp;&nbsp;[-]</a><br /><div id='" + divPhoneNumber + "' />";
	contentID.appendChild(newTBDiv);*/
	
};

var removeFixedNumber = function(intText){
	if(intText != 0)
	{
		var contentID = document.getElementById("fixed-col");
		contentID.removeChild(document.getElementById("strTextPn"+intText));
		//intTextBox = intTextBox-1;
	}
};

var ajax1=new sack();

//CHECKING UNIQUE DRIVER ID FOR ADMIN

function checkDevice(tableName,condStr,val,id)
{
	val = val.replace(" ","_");
	qry = "select * from "+tableName+" where di_status = 1 AND "+condStr+" = '"+val+"'";
		
	ajax1.requestFile = 'ajax_server.php?ajaxQry='+qry;
	//document.write(ajax1.requestFile);
	ajax1.onCompletion = function(){resultDevice(id)};
	ajax1.runAJAX();
}

function resultDevice(id)
{
  if(ajax1.response ==1 )
  {
  	alert("Data already Exist");
  	document.getElementById(id).value = '';
	document.getElementById(id).focus();
  }
	
}
function cancelEditDev(uid,cid,act)
{
	document.frmSubmit.txtDeviceId.value = uid;
	document.frmSubmit.txtClientId.value = cid;
	document.frmSubmit.action = act;
	document.frmSubmit.submit();
}
function passModel(modelVal)
{
	qry = "select * from tb_device_model where id = "+modelVal;
	ajax1.requestFile = 'ajax_server.php?getResQryWithHash='+qry;
	//document.write(ajax1.requestFile);
	ajax1.onCompletion = function(){resultModel(modelVal)};
	ajax1.runAJAX();
}
var val, val1;
function resultModel(modelVal)
{
	val1 = ajax1.response;
	val = val1.split("#");
	
	document.getElementById('txtNoofInput').value = val[5];
	document.getElementById('txtNoofOutput').value = val[6]; 
	document.getElementById('txtNoofAnalog').value = val[7]; 
	
	blockFuelPort(0,val[5],'IN','portInputTable');
	blockFuelPort(0,val[6],'OUT','portOutputTable');
	blockFuelPort(0,val[7],'ANA','portAnalogTable');
	
	if(val[12] != "")
	document.getElementById('devDiagram').innerHTML = '<a href="#" class="info_port">Pin Diagram<span><img src="images/'+val[12]+'"/></span></a>';
	else 
	document.getElementById('devDiagram').innerHTML = "";

	if(val[9] == 1)
	{
		document.getElementById('isImmobalize').style.display = 'block';
		document.getElementById('noImmobalize').style.display = 'none';
	}
	else
	{
		document.getElementById('isImmobalize').style.display = 'none';
		document.getElementById('noImmobalize').style.display = 'block';
	}
}
function blockFuelPort(yFuel,inputVal,pre,tableDisp)
{
	if(document.getElementById('txtDeviceModel').value != 0)
	{
		if(inputVal > 0)
		{
			if(yFuel == 1)	
			inputVal -=1;
			
			var portTableData = '<table>';
			for(i=1;i<=inputVal;i++)
			{
				portTableData += '<tr><td>Label&nbsp;<input type="text" id="txt'+pre+'LabelInput'+i+'" value="Label '+i+'" name="txt'+pre+'LabelInput'+i+'" style="width:41%;" /></td><td>Port no&nbsp;<input type="text" id="txt'+pre+'Input'+i+'" name="txt'+pre+'Input'+i+'" value="0" style="width:20%;" /></td></tr>';
				if(pre == "ANA")
				{
					//portTableData += '';
					//portTableData += '<tr><td colspan="2"><table id="divFixedNumber'+i+'"><tr><td>Tank Size&nbsp;<input type ="text" name="tanksize'+i+'[]" id="tanksize'+i+'" style="width:70px;" maxlength="5" value=""></td><td>Voltage&nbsp;<input type="text" name="voltage'+i+'[]" style="width:70px;" value="" id="voltage'+i+'" maxlength="8" /><a href="javascript:void(0)" onclick="addRow('+i+')">[+]</a></td></tr></table></td></tr>';
					portTableData += '<tr><td colspan="2"><table width="100%" id="divFixedNumber'+i+'" class="portGrid"><tr><th width="2%">#</th><th style="width:41%;">Tank Size</th><th style="width:41%;">Voltage</th><th width="5%"><a href="javascript:void(0)" onclick="addRow('+i+',\'\',\'\')">[+]</a></th></tr></table></td></tr>';
					
				}
			}
			
			portTableData += '</table>';
			document.getElementById(tableDisp).innerHTML = portTableData;
		}
		else
		{
			document.getElementById(tableDisp).innerHTML = "NA";
		}
	}
	else
	{
		alert("Please select Device Model first");
		document.getElementById('txtDeviceModel').focus();
		document.getElementById('txtNeedfuel').checked = false;
		$('tr#fuel_details').hide();
	}
}
</script>

<div class="pagearea"><!-- Pagearea div start here -->
<!--<div align="left" class="listofusers"><a href="#" onclick="location.href='?ch=viewClientDevice';">List of Device</a> / Add Device</div>
-->
<form name="frmDeviceRegister" id="frmDeviceRegister" action="?ch=Device" method="post" enctype="multipart/form-data">
<input type="hidden" name="txtClientId" id="txtClientId" value="<?php echo $_POST[txtClientId];?>"/>  
<input type="hidden" name="txtClientUserId" id="txtClientUserId" value="<?php echo $clientRecord[ui_id];?>"/>
<input type="hidden" name="txtNeedfuel" id="txtNeedfuel" value="<?php echo $deviceRecord[di_fuel];?>" />
<input type="hidden" name="txtNoofInput" id="txtNoofInput" value="<?php echo $totInput;?>" />
<input type="hidden" name="txtNoofOutput" id="txtNoofOutput" value="<?php echo $totOutput;?>" />
<input type="hidden" name="txtNoofAnalog" id="txtNoofAnalog" value="<?php echo $totAnalog;?>" />
<?php
if(isset($_POST[txtDeviceId]) && $_POST[txtDeviceId] !=''){
?>
	<input type="hidden" name="txtDeviceId" id="txtDeviceId" value="<?php echo $_POST[txtDeviceId];?>"/>  
<?php } ?>
<table class="gridform_final">
<tr>
    <td>Client </td>
    <td><?php echo ucfirst($clientRecord[ci_clientName]);?></td>
    <td>Device Id </td>         
    <td>
        <?php 
		 
		 /*if($recordUserInfo[ci_clientType] == "Reseller"){?>
          <input type="text" id="txtDeviceUnId" name="txtDeviceUnId" value="<?php echo $deviceRecord[di_deviceId];?>" onblur="checkDevice('tb_deviceinfo','di_deviceId',this.value,this.id);"  />
		 <?php } else*/ if(isset($_POST[txtDeviceId]) && $_POST[txtDeviceId] !=''){ ?>
       <input type="text" id="txtDeviceUnId" name="txtDeviceUnId" readonly="readonly" value="<?php echo $deviceRecord[di_deviceId];?>" />
        <?php } else { ?>
        <input type="text" id="txtDeviceUnId" name="txtDeviceUnId" value="<?php echo $deviceRecord[di_deviceId];?>" onblur="checkDevice('tb_deviceinfo','di_deviceId',this.value,this.id);"  />
        <?php } ?>
     </td>
  </tr>
   <tr>
        <td>Device Name</td>
        <td>
        <input type="text" id="txtDeviceName" name="txtDeviceName" value="<?php echo $deviceRecord[di_deviceName];?>" onblur="checkDevice('tb_deviceinfo','di_deviceName',this.value,this.id);"  /> </td>
        <td colspan="2">&nbsp;</td>
  </tr>
      <tr>
        <td>IMEI </td>
        <td>
         <?php 
		 /*if($recordUserInfo[ci_clientType] == "Reseller"){?>
          <input type="text" id="txtImeiNo" name="txtImeiNo" value="<?php echo $deviceRecord[di_imeiId];?>" onblur="checkDevice('tb_deviceinfo','di_imeiId',this.value,this.id);"/>
         <?php } else*/ if(isset($_POST[txtDeviceId]) && $_POST[txtDeviceId] !=''){ ?>
         <input type="text" id="txtImeiNo" name="txtImeiNo" value="<?php echo $deviceRecord[di_imeiId];?>" />
         <?php } else { ?>
         <input type="text" id="txtImeiNo" name="txtImeiNo" value="<?php echo $deviceRecord[di_imeiId];?>" onblur="checkDevice('tb_deviceinfo','di_imeiId',this.value,this.id);"/>
        <?php } ?>
		         <input type="hidden" id="txtfImeiNo" name="txtfImeiNo" value="<?php echo $deviceRecord[di_imeiId];?>" />
     </td>
        <td>Mobile No </td>
        <td>
        	<?php if(isset($_POST[txtDeviceId]) && $_POST[txtDeviceId] !='') { ?>
         <input type="text" id="txtMobileNo" name="txtMobileNo" value="<?php echo $deviceRecord[di_mobileNo];?>"/>
         <?php } else { ?>
         <input type="text" id="txtMobileNo" name="txtMobileNo" onblur="checkDevice('tb_deviceinfo','di_mobileNo',this.value,this.id);" value="<?php echo $deviceRecord[di_mobileNo];?>"/>
         <?php } ?>
   </td>     
  </tr>
  
  <tr>
        <td>Odometer Reading</td>         
        <td><input type="text" id="txtOdometer" name="txtOdometer" value="<?php echo $deviceRecord[di_odoMeter];?>"/> </td>     
        <td>Device Model</td>
        <td>
        <?php if($recordUserInfo[ci_clientType] != "Client") { ?>
		<select id="txtDeviceModel" name="txtDeviceModel" onchange="passModel(this.value)">
		  <option value='0'>Select Model</option>
		  <?php while($dev_model_results = $db->fetch_array($model_rows)){?>
          <option value='<?php echo $dev_model_results[id];?>' 
		  <?php if(strtolower($dev_model_results[id])==strtolower($deviceRecord[di_deviceModel])){echo 'selected';}?>><?php echo $dev_model_results[tdm_aliasName];?></option>
		  <?php }?>
		</select>
        <?php } else { ?>
        <select id="txtDeviceModel" name="txtDeviceModel" >
		  <option value="<?php echo $deviceRecord[di_deviceModel];?>"><?php echo $deviceRecord[tdm_aliasName];?></option>
          </select>
        <?php  } ?>
        <span id="devDiagram">
        <?php if($deviceRecord[tdm_diagram]) { ?>
        	<a href="#" class="info_port">Pin Diagram<span><img src="images/<?php echo $deviceRecord[tdm_diagram];?>" /></span></a>
        <?php } ?>
        </span>
	  </td>     
  </tr>
	<?php if($recordUserInfo[ci_clientType] != "Client") { ?>
      <tr>
            <td>Enable Immbalize / Speed Alaram </td>
            <td>
            <?php 
            if(isset($deviceRecord[di_deviceModel]))
            {
                if($deviceRecord[tdm_immobFunc] == 1)
                {
                    ?>
                    <span id="isImmobalize" style="display:block">
                        <input type="checkbox" value="1" id="txtIsImmobalize" name="txtIsImmobalize" <?php if($deviceRecord[di_immoblize]!='0'){echo 'checked';}?>/>
                    </span>
                    <span id="noImmobalize" style="display:none">Not avilable to This Model
                        <input type="hidden" id="txtNoImmobalize" name="txtNoImmobalize" value="0" />
                    </span>
                    <?php
                }
                else
                {
                    ?>
                    <span id="isImmobalize" style="display:none">
                        <input type="checkbox" value="1" id="txtIsImmobalize" name="txtIsImmobalize" <?php if($deviceRecord[di_immoblize]!='0'){echo 'checked';}?>/>
                    </span>
                    <span id="noImmobalize" style="display:block">Not avilable to This Model
                        <input type="hidden" id="txtNoImmobalize" name="txtNoImmobalize" value="0" />
                    </span>
                    <?php
                }
            } 
            else 
            {
            ?>
            <span id="isImmobalize" style="display:block">
                <input type="checkbox" value="1" id="txtIsImmobalize" name="txtIsImmobalize" <?php if($deviceRecord[di_immoblize] == 1){echo 'checked';}?>/>
            </span>
            <span id="noImmobalize" style="display:none">Not avilable to This Model
                <input type="hidden" id="txtNoImmobalize" name="txtNoImmobalize" value="0" />
            </span>
            <?php } ?>
            </td>   
            <td>Status</td>
            <td><input type="checkbox" value="1" id="txtStatus" <?php if($_POST[txtDeviceId]!='') { if($deviceRecord[di_status] == 1) echo 'checked="checked"'; } else {echo 'checked="checked"';}  ?>  name="txtStatus" />
          </td>  
          </tr>
  <?php }else { ?>
 	<input type="hidden" name="txtStatus" id="txtStatus" value="1" />
 <?php } ?>
  <tr>
  	<td colspan="4">
    <div style="height:250px; overflow-Y:scroll;" id="portDiv">
    	<table border="0" width="100%">
        	  <tr>
                <th width="33%" class="formtext" style="vertical-align:top">Digital Input Port Details </th>
                <th width="33%" class="formtext" style="vertical-align:top">Digital Output Port Details </th>
                <th width="35%" class="formtext" style="vertical-align:top">Analog Port Details </th>
              </tr>
              <tr>
                <td id="portInputTable" style="vertical-align:top">
                <?php 
                    if($deviceRecord[di_inputPort]!='' && $totInput!="")
                    {
                        $portDetails1 = explode("#",$deviceRecord[di_inputPort]);
					    $portTab = "<table>";
						for($k=1;$k<=$totInput;$k++)
						{						
							if($portDetails1[$k-1]!="")
							{
								$portDetails2 = explode("_",$portDetails1[$k-1]);
								$portTab .= '<tr><td>Label&nbsp;<input type="text" id="txtINLabelInput'.$k.'" value="'.$portDetails2[0].'" name="txtINLabelInput'.$k.'" style="width:41%;" /></td><td>Port no&nbsp;<input type="text" id="txtINInput'.$k.'" name="txtINInput'.$k.'" value="'.$portDetails2[1].'" style="width:20%;" /></td></tr>';
								}
								else
								{
									$portTab .= '<tr><td>Label&nbsp;<input type="text" id="txtINLabelInput'.$k.'" value="Label'.$k.'" name="txtINLabelInput'.$k.'" style="width:41%;" /></td><td>Port no&nbsp;<input type="text" id="txtINInput'.$k.'" name="txtINInput'.$k.'" value="0" style="width:20%;" /></td></tr>';
								}
						}
						$portTab .= "</table>";                        
                        echo $portTab;
                    }
					else if($deviceRecord[di_inputPort]=='' && $totInput!="")
                    {
					    $portTab = "<table>";
						for($k=1;$k<=$totInput;$k++)
						{						
							$portTab .= '<tr><td>Label&nbsp;<input type="text" id="txtINLabelInput'.$k.'" value="Label'.$k.'" name="txtINLabelInput'.$k.'" style="width:41%;" /></td><td>Port no&nbsp;<input type="text" id="txtINInput'.$k.'" name="txtINInput'.$k.'" value="0" style="width:20%;" /></td></tr>';
						}
						$portTab .= "</table>";                        
                        echo $portTab;
                    }
                    else
                    {
                        echo "Choose Device Model";
                    }
                ?>
                
                </td>
                <td id="portOutputTable" style="vertical-align:top">
                <?php 
                    if($deviceRecord[di_outputPort]!='' && $totOutput!='')
                    {
                        $portDetails1 = explode("#",$deviceRecord[di_outputPort]);                        
						$portTab = "<table>";
						for($k=1;$k<=$totOutput;$k++)
						{
							if($portDetails1[$k-1])
							{
								$portDetails2 = explode("_",$portDetails1[$k-1]);
								$portTab .= '<tr><td>Label&nbsp;<input type="text" id="txtOUTLabelInput'.$k.'" value="'.$portDetails2[0].'" name="txtOUTLabelInput'.$k.'" style="width:41%;" /></td><td>Port no&nbsp;<input type="text" id="txtOUTInput'.$k.'" name="txtOUTInput'.$k.'" value="'.$portDetails2[1].'" style="width:20%;" /></td></tr>';
							}
							else
							{
								$portTab .= '<tr><td>Label&nbsp;<input type="text" id="txtOUTLabelInput'.$k.'" value="Label'.$k.'" name="txtOUTLabelInput'.$k.'" style="width:41%;" /></td><td>Port no&nbsp;<input type="text" id="txtOUTInput'.$k.'" name="txtOUTInput'.$k.'" value="0" style="width:20%;" /></td></tr>';
							}
								
						}
						$portTab .= "</table>";
                        echo $portTab;
                    }
					else if($deviceRecord[di_outputPort]=='' && $totOutput!='')
                    {
						$portTab = "<table>";
						for($k=1;$k<=$totOutput;$k++)
						{
							$portTab .= '<tr><td>Label&nbsp;<input type="text" id="txtOUTLabelInput'.$k.'" value="Label'.$k.'" name="txtOUTLabelInput'.$k.'" style="width:41%;" /></td><td>Port no&nbsp;<input type="text" id="txtOUTInput'.$k.'" name="txtOUTInput'.$k.'" value="0" style="width:20%;" /></td></tr>';							
								
						}
						$portTab .= "</table>";
                        echo $portTab;
                    }
                    else
                    {
                        echo "Choose Device Model";
                    }
                ?>
                
                </td>
                <td id="portAnalogTable" style="vertical-align:top">
                <?php 
                    if($deviceRecord[di_analogPort]!='' && $totAnalog!='')
                    {
                        $portDetails1 = explode("@",$deviceRecord[di_analogPort]);
						echo  "<table>";
						for($k=1;$k<=$totAnalog;$k++)
						{
							if($portDetails1[$k-1])
							{	
								//echo $portDetails1[$k-1]."<br>";
								$d1 = explode("=",$portDetails1[$k-1]);
								$d2 = substr($d1[1],0,strpos($d1[1],"("));
								$d3 = str_replace(")","",substr($d1[1],(strpos($d1[1],"(")+1)));    	                            
								echo '<tr><td>Label&nbsp;<input type="text" id="txtANALabelInput'.$k.'" value="'.$d1[0].'" name="txtANALabelInput'.$k.'" style="width:41%;" /></td><td>Port no&nbsp;<input type="text" id="txtANAInput'.$k.'" name="txtANAInput'.$k.'" value="'.$d2.'" style="width:20%;" /></td></tr>';
								
								echo  '<tr><td colspan="2"><table width="100%" id="divFixedNumber'.$k.'" class="portGrid"><tr><th width="2%">#</th><th style="width:41%;">Tank Size</th><th style="width:41%;">Voltage</th><th width="5%"><a href="javascript:void(0)" onclick="addRow('.$k.',\'\',\'\')">[+]</a></th></tr></table></td></tr>';
								
								if(strlen($d3) > 0)
								{
								?>
								<script language="javascript">
									generateRow('<?php echo $k;?>','<?php echo $d3;?>');
								</script>
								<?php
								}
							}
							else
							{
								echo  '<tr><td>Label&nbsp;<input type="text" id="txtLabelInput'.$k.'" value="Label'.$k.'" name="txtANALabelInput'.$k.'" style="width:41%;" /></td><td>Port no&nbsp;<input type="text" id="txtANAInput'.$k.'" name="txtANAInput'.$k.'" value="'.$k.'" style="width:20%;" /></td></tr>';
								echo  '<tr><td colspan="2"><table width="100%" id="divFixedNumber'.$k.'" class="portGrid"><tr><th width="2%">#</th><th style="width:41%;">Tank Size</th><th style="width:41%;">Voltage</th><th width="5%"><a href="javascript:void(0)" onclick="addRow('.$k.',\'\',\'\')">[+]</a></th></tr></table></td></tr>';
							}
						}
						echo  "</table>";
                        
                        //echo $portTab;
                    }
                    else if($deviceRecord[di_analogPort]=='' && $totAnalog!='')
                    {
                        $portTab = "<table>";
                        for($k=1;$k<=$totAnalog;$k++)
                        {
                            $portTab .= '<tr><td>Label&nbsp;<input type="text" id="txtLabelInput'.$k.'" value="Label'.$k.'" name="txtANALabelInput'.$k.'" style="width:41%;" /></td><td>Port no&nbsp;<input type="text" id="txtANAInput'.$k.'" name="txtANAInput'.$k.'" value="'.$k.'" style="width:20%;" /></td></tr>';
							
							$portTab .= '<tr><td colspan="2"><table width="100%" id="divFixedNumber'.$k.'" class="portGrid"><tr><th width="2%">#</th><th style="width:41%;">Tank Size</th><th style="width:41%;">Voltage</th><th width="5%"><a href="javascript:void(0)" onclick="addRow('.$k.',\'\',\'\')">[+]</a></th></tr></table></td></tr>';
                        }
                        $portTab .= "</table>";
                        echo $portTab;
                    }
                    else
                    {
                        echo "Choose Device Model";
                    }
                ?>
                
                </td>
          </tr>
        </table>
     </div>
    </td>
  </tr>
   <tr valign="top">
      <td valign="top">Image </td>
      <td> <input type="file" name="fileDeviceLogo" id="fileDeviceLogo" /> </td>
     <td valign="top">Map Icon </td>
	      <td>
      <input type="radio"  name="rdDevImg" id="rdDevImg_1" value="tank1.png" <?php if(!isset($deviceRecord[di_mapIcon]) || $deviceRecord[di_mapIcon] == 'tank1.png') echo 'checked="checked"';?> /><img src="unit_img/tank1.png" height="55" width="55" />&nbsp;
      <input type="radio" name="rdDevImg" id="rdDevImg_2" value="Car1.png" <?php if(isset($deviceRecord[di_mapIcon]) && $deviceRecord[di_mapIcon] == 'Car1.png') echo 'checked="checked"';?> /><img src="unit_img/Car1.png" height="55" width="55" />&nbsp;
      <input type="radio" name="rdDevImg" id="rdDevImg_3" value="lorry1.png" <?php if(isset($deviceRecord[di_mapIcon]) && $deviceRecord[di_mapIcon] == 'lorry1.png') echo 'checked="checked"';?> /><img src="unit_img/lorry1.png" height="55" width="55" />&nbsp;
      <input type="radio" name="rdDevImg" id="rdDevImg_4" value="boat2.png" <?php if(isset($deviceRecord[di_mapIcon]) && $deviceRecord[di_mapIcon] == 'boat2.png') echo 'checked="checked"';?> /><img src="unit_img/boat2.png" height="55" width="55" />&nbsp;
      <input type="radio" name="rdDevImg" id="rdDevImg_4" value="bus1.png" <?php if(isset($deviceRecord[di_mapIcon]) && $deviceRecord[di_mapIcon] == 'bus1.png') echo 'checked="checked"';?> /><img src="unit_img/bus1.png" height="55" width="55" /></td>
  </tr>

  <tr><td colspan="4" style="text-align:center">
	  <?php
      if(isset($_POST[txtDeviceId]) && $_POST[txtDeviceId] !='')
        {
        ?>
            <input type="submit" name="cmdSubmitClientUpdateDevice" id="cmdSubmitClientUpdateDevice" value="Update" class="save_btn" />
            <?php if($recordUserInfo[ci_clientType] == "Reseller"){?>
            <input type="button" class="save_btn" name="cmdCancel" id="cmdCancel" onclick="cancelEditDev('','<?php echo $_POST[txtClientId];?>','?ch=viewClientDevice');" value="Cancel" />
            <?php } else { ?>
            <input type="button" class="save_btn" name="cmdCancel" id="cmdCancel" onclick="cancelEditDev('','<?php echo $_POST[txtClientId];?>','?ch=viewDevice');" value="Cancel" />
            <?php } ?>
      <?php } else { ?>
            <input type="submit" name="cmdSubmitClientAddDevice" id="cmdSubmitClientAddDevice" value="Submit" class="save_btn" />
            <input type="reset" value="Reset" class="save_btn" />
      <?php } ?>
  </td></tr>
</table>
        
</form>
 <script language="JavaScript" type="text/javascript">
//You should create the validator only after the definition of the HTML form
  var frmvalidator  = new Validator("frmDeviceRegister");
  
  frmvalidator.addValidation("txtDeviceUnId","req","Please enter Device ID");
  frmvalidator.addValidation("txtDeviceUnId","minlen=5","Min length for Device ID is 5");
  
  if(document.frmDeviceRegister.txtDeviceName)
  frmvalidator.addValidation("txtDeviceName","req","Please enter Device Name");
  
  frmvalidator.addValidation("txtImeiNo","maxlen=50");
  frmvalidator.addValidation("txtImeiNo","req","Please enter imei number");
  frmvalidator.addValidation("txtImeiNo","numeric","Please enter valid numbers");

  //frmvalidator.addValidation("txtfullTanksize","numeric","Please enter valid numbers");
  //frmvalidator.addValidation("txthalfTanksize","numeric","Please enter valid numbers");
 // frmvalidator.addValidation("txtfullTanksignal","numeric","Please enter valid numbers");
 // frmvalidator.addValidation("txtemptyTanksignal","numeric","Please enter valid numbers");
  //frmvalidator.addValidation("txtFuelport","numeric","Please enter valid numbers");
//  frmvalidator.addValidation("txtAcport","numeric","Please enter valid numbers");
//  frmvalidator.addValidation("txtIgport","numeric","Please enter valid numbers");
//  frmvalidator.addValidation("txtSosport","numeric","Please enter valid numbers");
//  frmvalidator.addValidation("txtEngineport","numeric","Please enter valid numbers");
  
  frmvalidator.addValidation("txtMobileNo","maxlen=50");
  frmvalidator.addValidation("txtMobileNo","req","Please enter Mobile number");
  frmvalidator.addValidation("txtMobileNo","numeric","Please enter valid Mobile numbers");

  frmvalidator.addValidation("txtOdometer","maxlen=50");
  frmvalidator.addValidation("txtOdometer","req","Please enter Odometer Reading");
  frmvalidator.addValidation("txtOdometer","numeric","Please enter valid Reading");
  
   if(!document.frmDeviceRegister.txtDeviceName)
  frmvalidator.addValidation("txtDeviceModel","dontselect=0","Please enter Device Model");
 // frmvalidator.addValidation("txtDeviceModel","req","Please enter Device Model");
  
</script>   
</div><!-- PAGEarea END here -->

<form name="frmSubmit" id="frmSubmit" method="post">
	<input type="hidden" name="txtDeviceId" id="txtDeviceId" />
    <input type="hidden" name="txtClientId" id="txtClientId" />
</form>